package com.mall.huohuo.openapi.config.datasource;

import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import com.github.pagehelper.PageInterceptor;
import com.mall.huohuo.common.constant.EnvironmentNameConstants;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import javax.sql.DataSource;

/**
 * @author zycoding
 */
@Configuration
@MapperScan(basePackages = {"com.mall.huohuo.datasource.mapper"})
public class MybatisPlusConfig {

    /**
     * SQL执行效率插件
     */
    @Bean
    @Profile({EnvironmentNameConstants.DEFAULT, EnvironmentNameConstants.DEV, EnvironmentNameConstants.TEST})
    public PerformanceInterceptor performanceInterceptor() {
        return new PerformanceInterceptor();
    }

    /**
     * 分页插件
     */
    @Bean
    public PageInterceptor pageInterceptor(DataSource dataSource) {
        System.out.println(dataSource);
        System.out.println("dataSource" + dataSource);
        final PageInterceptor pageInterceptor = new PageInterceptor();
        return pageInterceptor;

    }
}
